/* eslint-disable no-console */
/* eslint-disable n/prefer-global/process */
const fs = require('node:fs');
const yaml = require('js-yaml');

const args = process.argv.slice(2);
console.log(args);
const jsfilepath = args[0];
if (jsfilepath) {
  const jsobj = require(jsfilepath);
  console.log(jsobj);
  const yamlString = yaml.dump(jsobj);
  fs.writeFileSync(`${jsfilepath}.yaml`, yamlString);
  jsobj_en = {};
  jsobj_zh = {};

  for (const key in jsobj) {
    if (Object.hasOwnProperty.call(jsobj, key)) {
      const element = jsobj[key];
      
      const v2 = element.split('#');
      if (v2.length == 2) {
        jsobj_en[key] = v2[0];
        jsobj_zh[key] = v2[1];
      } else {
        console.log(v2);
      }
    }
  }
  const yamlStringEn = yaml.dump(jsobj_en);
  fs.writeFileSync(`${jsfilepath}-en.yaml`, yamlStringEn);
  const yamlStringZh = yaml.dump(jsobj_zh);
  fs.writeFileSync(`${jsfilepath}-zh.yaml`, yamlStringZh);
}
